#!/bin/sh

if [ "$1" = "autoconf" ]; then
	if which apcaccess > /dev/null; then
		echo yes
		exit 0
	else
		echo no
		exit 0
	fi
fi

if [ "$1" = "config" ]; then
	cat <<EOF
graph_title UPS Power
graph_category sensors
graph_vlabel Watts
graph_args --base 1000 -l 0
graph_info UPS power measurements
nompower.label Nominal power output
loadpower.label Load power usage
EOF
	exit 0
fi

apcaccess -u | awk '
/:/ {
	a[tolower($1)] = $3
}
END {
	print "nompower.value",  a["nompower"]
	print "loadpower.value", a["nompower"] * (a["loadpct"] / 100)
}
'
